package edu.ccut.saturn.workflow.activity.execute;

import java.util.List;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class CompositeStringfromList extends DefaultComponent {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5082232707400060526L;

	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		List<Object> resource= (List<Object>)parameterContext.getParameterValue(0);
		Boolean addSingleQuote = (Boolean)parameterContext.getParameterValue(1);
		String singleQuote = "";
		if(addSingleQuote){
			singleQuote = "'";
		}
		StringBuffer result = new StringBuffer();
		for(Object item :resource){
			result.append(singleQuote);
			result.append(item);
			result.append(singleQuote);
			result.append(",");
		}
		result.deleteCharAt(result.length()-1);
		parameterContext.setParameter(2, result.toString());
	}
}